/*
 * QCalEventList.cpp
 *
 *  Created on: Aug 30, 2010
 *      Author: deroy2
 */
#include <QStackedWidget>
#include <QSettings>
#include <QWidget>
#include <QLineEdit>
#include <QPushButton>
#include <QVBoxLayout>
#include "QCalEventList.h"
#include "QCalDetailsWidget.h"
QCalEventList::QCalEventList(QStackedWidget* stackedWid,QVector<eventDetail>& dayEvents,QWidget *parent)
    //: QBaseWidget(stackedWidget,parent)
    {
	
	
    stackedWidget=stackedWid;
    eventDetails = dayEvents;
    listWidget = new QListWidget();
   	for(int i=0;i<dayEvents.count();i++)
   		{
		lst = new QListWidgetItem(dayEvents.at(i).title+"\n"+dayEvents.at(i).startTime, listWidget);
   //		itemArr.append(lst);
   		listWidget->addItem(lst);
   		
   		}
   	QPushButton* nxtButton = new QPushButton("&Prev Page", this);
   	QObject::connect(nxtButton, SIGNAL(clicked()),
   				                  this, SLOT(PrevPage()));
   
   QObject::connect(listWidget, SIGNAL(clicked(const QModelIndex &)),
    		                  this, SLOT(index(const QModelIndex &)));
   layout = new QVBoxLayout(); 
   layout->addWidget(listWidget);
    layout->addWidget(nxtButton);
    
    this->setLayout(layout);
   

    }
void QCalEventList::PrevPage()
	{
	//stackedWidget->currentWidget()->setHidden(true);
	stackedWidget->removeWidget(this);//todo:delete newwidget
	stackedWidget->setCurrentIndex(0);
	stackedWidget->show();
	
//	//QMyWidget2* newWidget = new QMyWidget2(stackedWidget,eventArray,this);
//	QGoogleCalendar* newWidget=new QGoogleCalendar(this);
//	stackedWidget->removeWidget(this);
//	activateNewWidget(newWidget);
//	stackedWidget->addWidget(newWidget);
//	newWidget->show();
	}

void QCalEventList::index(const QModelIndex & in)
	{
	int row=in.row();
	NxtPage(eventDetails.at(row));
	}
QCalEventList::~QCalEventList()
    {
  if(listWidget)
	  delete listWidget;
//  if(lst)
//	  delete lst;
//  if(layout)
//	  delete layout;
    }

//void QMyWidget2::createMenus()
//    {
//    /*// Create menubar for this widget
//    // We sets these menu items into into QMainWindow menu when this widget is active
//    menuBar = new QMenuBar();
//
//    menuAction = new QAction("Hello QMyWidget2",menuBar);
//    menuBar->addAction(menuAction);
//    connect(menuAction, SIGNAL(triggered()),this, SLOT(hello()));*/
//    }
//
//QMenuBar* QMyWidget2::MenuBar() const
//    {
//  //  return menuBar;
//    }

void QCalEventList::NxtPage(eventDetail event)
	{

	QCalDetailsWidget* newWidget = new QCalDetailsWidget(stackedWidget,event,listWidget);
	
	stackedWidget->removeWidget(listWidget);
	//delete listWidget;
	//activateNewWidget(newWidget);	
	stackedWidget->addWidget(newWidget);	
	stackedWidget->setCurrentWidget(newWidget);
	stackedWidget->show();
	}
